package main

import (
	"context"
	"fmt"
	stdlog "log"

	"go-distributed/log"
	"go-distributed/registry"
	"go-distributed/service"
)

func main() {

	log.Run("./distributed.log")
	host, port := "localhost", "4000"
	serviceAddress := fmt.Sprintf("http://%s:%s", host, port)

	reg := registry.Registration{
		ServiceName:      registry.LogService,
		ServiceUrl:       serviceAddress,
		RequireServices:  make([]registry.ServiceName, 0),
		ServiceUpdateUrl: serviceAddress + "/services",
	}
	ctx, err := service.Start(context.Background(), host, port, reg, log.RegisterHandlers)

	if err != nil {
		stdlog.Fatalln(err)
	}
	<-ctx.Done()

	fmt.Println("Shutting down log service.")

}
